<template>
    <el-dialog v-model="dialogFormVisible" :title="title" @close="closeDialog" width="80%" top="40px">
        <baseWageDetailView ref="baseWageDetailView" />
        <addFileView ref="addFileView" />
        <div class="app-table">
            <div class="app-body">
                <div class="app-search">
                    <el-form :inline="true" class="demo-form-inline" v-model="form">
                        <el-form-item label="人员工号">
                            <el-input placeholder="请输入人员工号" v-model="form.teacherNumber"></el-input>
                        </el-form-item>
                        <el-form-item label="人员姓名">
                            <el-input placeholder="请输入人员姓名" v-model="form.teacherName"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button class="serach_btn" type="primary" @click="onSubmit"
                                @keyup.enter="searchEnter">搜索</el-button>
                            <el-button class="add_btn" type="warning" @click="exportExcel">导出报表</el-button>
                        </el-form-item>
                    </el-form>
                </div>
                <el-table size="default" :data="list" style="width: 100%" :row-class-name="tableRowClassName">
                    <el-table-column type="index" label="序号" width="100"/>
                    <el-table-column prop="wageMonth" label="月份" />
                    <el-table-column prop="teacherName" label="人员姓名" />
                    <el-table-column prop="teacherNumber" label="人员工号" />
                    <!-- <el-table-column prop="teacherWageTypeId" label="工资条目id"/>
                                <el-table-column prop="teacherWageTypeName" label="工资条目名称"/>
                                <el-table-column prop="wageType" label="工资类型id"/>
                                <el-table-column prop="wageTypeName" label="工资类型名称"/>
                                <el-table-column prop="isStatistics" label="是否统计"/> -->
                    <el-table-column prop="wages" label="工资金额" />
                    <!-- <el-table-column prop="campus" label="校区"/> -->
                    <!-- <el-table-column prop="wageStructure" label="工资结构1应发工资、2应扣工资"/> -->
                    <!-- <el-table-column prop="uuid" label="uuid"/> -->
                    <!-- <el-table-column prop="createTime" label="创建时间"/> -->
                    <el-table-column label="操作" width="210px">
                        <template style="display: block" #default="scope">
                            <el-button class="edit_btn" size="small" type="success"
                                @click="editBaseWage(scope.row)">工资明细
                            </el-button>
                            <el-button class="del_btn" size="small" type="danger" @click="deleteBaseWage(scope.row)">删除
                            </el-button>
                        </template>
                    </el-table-column>
                    <template v-slot:empty>
                        <el-empty description="暂无数据"></el-empty>
                    </template>
                </el-table>
                <el-config-provider :locale="locale">
                    <el-pagination :total="total" :page-size="limit" :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
                        layout="total, sizes, prev, pager, next, jumper" @size-change="changePageSize"
                        @current-change="changeCurrentPage">
                    </el-pagination>
                </el-config-provider>
            </div>
        </div>
    </el-dialog>
</template>
<script>
import baseWageDetailView from "@/views/baseInfo/BaseWageDetailView.vue";
import addFileView from "@/components/addExcelFile.vue";
import { ElConfigProvider, ElMessageBox, ElMessage } from "element-plus";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import { httpService } from "@/utils/httpService";
import { Picture as IconPicture, Upload } from "@element-plus/icons-vue";
import { ref } from "vue";

export default {
    name: "BaseWageListView",
    data() {
        return {
            type: 0,
            title: "",
            dialogFormVisible: ref(false),

            page: 0,
            pageSize: 10,
            total: 0,
            limit: 10,
            list: [],
            form: {
                teacherNumber: "",
                teacherName: "",
                teacherWageTypeName: "",
                wageTypeName: "",
                wageMonth: "",
                uuid: "",
            },
        };
    },
    components: {
        // addEditBaseWageView,
        addFileView,
        baseWageDetailView,
        IconPicture,
        ElConfigProvider,
        ElMessageBox,
        ElMessage, Upload
    },
    setup() {
        return {
            locale: zhCn,
        };
    },
    mounted() {
    },
    watch: {

    },
    methods: {
        searchEnter: function (e) {
            // 使用 which 和 keyCode 属性来解决兼容问题
            var keyCode = window.event ? e.keyCode : e.which;
            var val = e.target.value;
            if (keyCode == 13 && val) {
                this.getBaseWageList();
            }
        },
        add() {
            this.$refs.addEditBaseWageView.title = "添加"
            this.$refs.addEditBaseWageView.personnelType = this.type
            this.$refs.addEditBaseWageView.dialogFormVisible = true;
        },
        editBaseWage(obj) {
            this.$refs.baseWageDetailView.title = obj.teacherName + "的工资";
            this.$refs.baseWageDetailView.getBaseWageList(obj);
            this.$refs.baseWageDetailView.dialogFormVisible = true;
        },
        deleteBaseWage(obj) {
            ElMessageBox.confirm("确定要删除本条记录吗？", "提醒", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    let params = new FormData(); //创建一个form对象,必须是form对象否则后端接受不到数据
                    params.append("wageMonth", obj.wageMonth);
                    params.append("teacherNumber", obj.teacherNumber);

                    httpService("/javaApi/baseWage/deleteByTeacherNumberFoodMonth", params, "post").then(
                        (data) => {
                            if (data.code == 200) {
                                ElMessage.success("删除成功");
                                this.getBaseWageList();
                            } else {
                                ElMessage.error(data.message);
                            }
                        }
                    );
                })
                .catch(() => {
                });
        },
        reloadData() {
            this.page = 1;
            this.getBaseWageList()
        },
        importExcel() {
            this.$refs.addFileView.dialogFormVisible = true;
            this.$refs.addFileView.title = "批量导入";
            this.$refs.addFileView.uploadjavaApiUrl = "/javaApi/baseWage/importExcel";
        },
        exportExcel() {
            httpService(
                "/javaApi/baseWage/exportExcel",
                {
                    "teacherNumber": this.form.teacherNumber,
                    "teacherName": this.form.teacherName,
                    "teacherWageTypeName": this.form.teacherWageTypeName,
                    "wageTypeName": this.form.wageTypeName,
                    "wageMonth": this.form.wageMonth,
                    "uuid": this.form.uuid,
                },
                "get"
            ).then((data) => {
                if (data.code == 200) {
                    window.open(data.msg, '_blank')
                } else {
                    ElMessage.error(data.message)
                }
            });
        },
        onSubmit() {
            this.getBaseWageList();
        },
        // 每页记录数改变，size：回调参数，表示当前选中的“每页条数”
        changePageSize(size) {
            this.pageSize = size;
            this.limit = size;
            this.getBaseWageList();
        },

        // 改变页码，page：回调参数，表示当前选中的“页码”
        changeCurrentPage(page) {
            this.page = page;
            this.getBaseWageList();
        },
        tableRowClassName({ row, rowIndex }) {
            return "";
        },
        getBaseWageList() {
            httpService(
                "/javaApi/baseWage/listGroup/" + this.page + "/" + this.pageSize,
                {
                    "teacherNumber": this.form.teacherNumber,
                    "teacherName": this.form.teacherName,
                    "teacherWageTypeName": this.form.teacherWageTypeName,
                    "wageTypeName": this.form.wageTypeName,
                    "wageMonth": this.form.wageMonth,
                    "uuid": this.form.uuid,
                },
                "get"
            ).then((data) => {
                this.list = data.list;
                this.total = data.total;
                this.pageCount = data.pages;
            });
        },
    },
};
</script>
<style scoped>
.el-main {
    padding: 0px;
}

.teacher-content {
    width: 100%;
}

.app-table {
    /* background: #eff3f5; */
    /* padding: 10px; */
}

.app-search {
    margin-top: 0px;
}

.app-separator {
    padding-top: 10px;
    padding-bottom: 20px;
    padding-left: 10px;
}

.app-body {
    background: white;
    /* padding: 20px 20px 10px 20px; */
    margin-bottom: 10px;
    text-align: left;
}

.el-table .warning-row {
    --el-table-tr-bg-color: var(--el-color-warning-lighter);
}

.el-table .success-row {
    --el-table-tr-bg-color: var(--el-color-success-lighter);
}

.el-pagination {
    text-align: center;
    margin-top: 10px;
}

.serach_btn {
    background-color: #007EFF;
    color: #fff;
    border-radius: 8px;
    border: none;
}

.add_btn {
    background-color: #00c78c;
    color: #fff;
    border-radius: 8px;
    border: none;
}

.edit_btn {
    background-color: #fff;
    color: #007EFF;
    border: none;
}

.del_btn {
    background-color: #fff;
    color: #FF0000;
    border: none;
}

/* .el-dialog__header {
    padding-bottom: 10px;
} */
</style>
